package com.czztjj.springboottest.controller;


import com.czztjj.springboottest.entity.Person;
import com.czztjj.springboottest.entity.PersonMybatis;
import com.czztjj.springboottest.service.IPersonMybatisService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/test") // 127.0.0.1:8080/test/
@Slf4j
@RequiredArgsConstructor
public class TestController {

    public final Person person;

    private final IPersonMybatisService personMybatisService;

    @GetMapping("/hello-world")
    public String helloWorld(ModelMap modelMap) {
        modelMap.addAttribute("person", "Person 表格");
        modelMap.put("personMybatis", "Person 表格1");
        return "helloworld";
    }

    @GetMapping("/getTest")
    @ResponseBody
    public Person getTest(String id, String name) {
        log.info(id);
        log.info(name);

        return person;
    }

    @GetMapping("/getFromMysqlByMyBatis")
    @ResponseBody
    public List<PersonMybatis> getFromMysqlByMyBatis() {
        return personMybatisService.getFromMysqlByMyBatis();
    }



}
